// pkg_wo/pages/faPiaoAction/faPiaoAction.js
import request from '../../../utils/http.js'
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    winHeight:0,
    personId:0,
    list:[],
    allCheck:false,
    allJine:0,
    orderFormIdList:[],
    orderListStr:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    that.setData({
      personId:wx.getStorageSync(app.globalData.PERSON_ID),
    })
    //  高度自适应
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winHeight:  res.windowHeight-(180/750 * res.windowWidth),
        });
      }
    });

    that.getOrderList()
  },


  
  //获取订单信息
  getOrderList:function(){
    var that = this
    wx.showLoading({
      title: '加载中...',
      mask: true
    })



    request.get('faPiao/getOrderFormList', null, res => {
     
      console.log("我的订单:" + JSON.stringify(res.data))

      wx.hideLoading();

      that.setData({
        list:res.data.list,
      })
    
    }, err => {
      wx.showToast({
        title: '处理失败，请联系技术人员', // 提示的内容
        icon: "none", // 图标，默认success
        duration: 1000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
      wx.hideLoading();
    })

  },


  //全选
  idCheckAll: function () {
    var that=this

    that.setData({
      allCheck: !that.data.allCheck
    })

    var jine=0
    var tempList=[]
    var orderListStr=''
    var i=0
      that.data.list.forEach(function (item, index) {
       
        item.isCheck=that.data.allCheck
        if(that.data.allCheck){
          jine=jine+item.jinE
          tempList.push(item.orderFormId)
          if(i==0){
            orderListStr=item.orderFormId
          }else{
            orderListStr=orderListStr+','+item.orderFormId
          }
          i++
        }
        
      })
  
      // 更新数据，记录开始的位置
      that.setData({
        list: that.data.list,
        allJine:jine,
        orderFormIdList:tempList,
        orderListStr:orderListStr
      })
    

  },

  //选一个
  idCheckOne:function(e){
    var index=e.currentTarget.dataset.index
      this.data.list[index].isCheck=!this.data.list[index].isCheck;
      this.setData({
        list:this.data.list
      })
  
        var jine=0
        var tempAll=true
        var tempList=[]
        var orderListStr=''
        var i=0
        this.data.list.forEach(function (item, index) {
          if(item.isCheck){
            jine=jine+item.jinE
            tempList.push(item.orderFormId)
            if(i==0){
              orderListStr=item.orderFormId
            }else{
              orderListStr=orderListStr+','+item.orderFormId
            }
            i++

           
          }else{
            tempAll=false
          }
          
        })
    
        // 更新数据，记录开始的位置
        this.setData({
          allJine:jine,
          allCheck:tempAll,
          orderFormIdList:tempList,
          orderListStr:orderListStr
        })
      
  },


  //提交，传递参数给上一页
  itemClick: function(e) {
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    prevPage.setData({
      orderFormIdList: this.data.orderFormIdList,
      orderListStr:this.data.orderListStr,
      isSQBack:true,
    })
    wx.navigateBack({
         delta: 1,
    })
},


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})